﻿using System;
using System.Drawing;

internal sealed class modPublic
{
	public static IntPtr CreateMemoryDC(IntPtr hDC, int Width, int Height, ref IntPtr hOldBitmap)
	{
		IntPtr intPtr = API.CreateCompatibleDC(hDC);
		IntPtr hObject = API.CreateCompatibleBitmap(hDC, Width, Height);
		hOldBitmap = API.SelectObject(intPtr, hObject);
		API.DeleteObject(hObject);
		return intPtr;
	}

	public static void DrawLine(IntPtr hDC, int X1, int Y1, int X2, int Y2, int lpPenColor, int LineWidth, int LineStyle)
	{
		API.POINTAPI pointapi = default(API.POINTAPI);
		IntPtr hObject = API.CreatePen(LineStyle, LineWidth, lpPenColor);
		IntPtr hObject2 = API.SelectObject(hDC, hObject);
		API.MoveToEx(hDC, X1, Y1, ref pointapi);
		API.LineTo(hDC, X2, Y2);
		API.SelectObject(hDC, hObject2);
		API.DeleteObject(hObject);
		API.DeleteObject(hObject2);
	}

	public static void DrawPicture(IntPtr hDC, int X, int Y, int Width, int Height, Bitmap Source, int RopCode)
	{
		IntPtr intPtr = API.CreateCompatibleDC(hDC);
		IntPtr hbitmap = Source.GetHbitmap();
		IntPtr hObject = API.SelectObject(intPtr, hbitmap);
		API.BitBlt(hDC, X, Y, Width, Height, intPtr, 0, 0, RopCode);
		API.SelectObject(intPtr, hObject);
		API.DeleteDC(intPtr);
		API.DeleteObject(hbitmap);
	}

	public static void DrawPictureEx(IntPtr hDC, int X, int Y, int Width, int Height, Bitmap Source, int SrcX, int SrcY, int SrcWidth, int SrcHeight, int RopCode)
	{
		IntPtr intPtr = API.CreateCompatibleDC(hDC);
		IntPtr hbitmap = Source.GetHbitmap();
		IntPtr hObject = API.SelectObject(intPtr, hbitmap);
		int nStretchMode = API.SetStretchBltMode(hDC, 4);
		API.StretchBlt(hDC, X, Y, Width, Height, intPtr, SrcX, SrcY, SrcWidth, SrcHeight, RopCode);
		API.SetStretchBltMode(hDC, nStretchMode);
		API.SelectObject(intPtr, hObject);
		API.DeleteDC(intPtr);
		API.DeleteObject(hbitmap);
	}

	public static void DrawRectangle(IntPtr hDC, int X, int Y, int cx, int cy, int lpPenColor, int lpBrushColor, bool blnTransparent, int LineWidth)
	{
		if (cx >= 0 && cy >= 0)
		{
			IntPtr hObject = API.CreatePen(0, LineWidth, lpPenColor);
			IntPtr hObject2 = API.SelectObject(hDC, hObject);
			IntPtr hObject3;
			if (!blnTransparent)
			{
				hObject3 = API.CreateSolidBrush(lpBrushColor);
			}
			else
			{
				hObject3 = API.GetStockObject(5);
			}
			IntPtr hObject4 = API.SelectObject(hDC, hObject3);
			API.Rectangle(hDC, X, Y, X + cx, Y + cy);
			API.SelectObject(hDC, hObject4);
			API.DeleteObject(hObject3);
			API.DeleteObject(hObject4);
			API.SelectObject(hDC, hObject2);
			API.DeleteObject(hObject);
			API.DeleteObject(hObject2);
		}
	}

	public static int GetDarkColor(int Color, float Rate)
	{
		int num = (int)((float)(Color & 255) / Rate);
		int num2 = (int)((float)((Color & 65280) / 256) / Rate);
		int num3 = (int)((float)((Color & 16711680) / 65536) / Rate);
		return num + num2 * 256 + num3 * 65536;
	}

	public static int MulDiv(float Number, float Numerator, float Denominator)
	{
		return (int)(Number * Numerator / Denominator);
	}

	public static bool UseVisualStyles()
	{
		return Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major * 10 + Environment.OSVersion.Version.Minor >= 51 && API.IsAppThemed();
	}
}
